package com.waymap.Thread;

import com.waymap.common.Constant;
import com.waymap.utils.StringUtil;
import com.waymap.utils.mq.MsgProducer;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import javax.jms.Destination;

public class WmsThread extends Thread {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private MsgProducer producer;
    private String fromTransType;
    private String transactionId;
    private String transType;
    private String accountId;

    // 通过构造方法给线程名字赋值
    public WmsThread(String name, String transactionId, String fromTransType, MsgProducer producer, String transType,String accountId) {
        super(name);// 给线程名字赋值
        this.fromTransType = fromTransType;
        this.producer = producer;
        this.transactionId = transactionId;
        this.transType = transType;
        this.accountId = accountId;
    }

    // 重写run方法
    @Override
    public void run() {

        try {
            logger.info("*************************休眠1秒***************************");
            sleep(1000);//休息一秒
            logger.info("*************************休眠结束*******************************");
            Destination destination = new ActiveMQQueue(Constant.Queue_Name);
            logger.info("***********MQ数据推送*************" + transType + ":" + transactionId + ":" + fromTransType+":"+accountId);
            producer.sendMessage(destination, transType + ":" + transactionId + ":" + fromTransType+":"+accountId);
            logger.info("*************发送MQ完成********************");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }

}
